package com.eascs.spider.ant.schdule;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import com.eascs.spider.ant.common.util.RedisUtil;
import com.eascs.spider.ant.schdule.bloomfilter.BloomFilter;
import com.eascs.spider.ant.schdule.dispatcher.Dispatcher;
import com.eascs.spider.ant.schdule.monitor.Monitor;

/**
 * 调度中心启动
 *
 */
@SpringBootApplication
public class SchduleLauncher {
	private static Logger logger = LoggerFactory.getLogger(SchduleLauncher.class);
	
    public static void main( String[] args ){
    	SpringApplication.run(SchduleLauncher.class, args);
    }
    
    @Autowired
    Monitor monitor;
    
    @Autowired
    Dispatcher dispatcher;
    
    @Autowired
    BloomFilter bloomFilter;
    
    @PostConstruct
    public void init(){
    	//1,初始化布隆去重器
    	Object object = RedisUtil.initBloomFilter();
    	if(object !=null){
    		bloomFilter = (BloomFilter)object;
    		logger.info("布隆去重器从redis加载成功");
    	}
    	//2,启动监控器
    	monitor.start();
    }
    
    @PreDestroy
    public void destroy(){
    	RedisUtil.setBloomFilter(bloomFilter);
    	logger.info("执行销毁操作,布隆去重已成功持久化到redis");
    }
}
